package com.dmp.onlinestore.controller;

//import com.dmp.onlinestore.model.service.base.ServiceExecutionException;

import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;

import com.dmp.onlinestore.view.base.ViewAddressFactory;

public class ActionHandlerNoAction extends ActionHandler {
	
	public ActionHandlerNoAction(HttpServletRequest request, HttpServletResponse response) {
		super(request, response);
	}
	
	protected void validate() throws ControllerValidationException {
		// There should be no parameters.
		Map params = getParmMap();
		if (params.keySet().size() != 0) {
			throw new ControllerInternalValidationException("Non-null list of input parameters for ActionHandlerNull.");
		}
	}

	// Update this later to use application-defined (global) string constants instead
	// of hard-coded strings.
	protected void process() throws ControllerException {
		// Get list of all PersonBean's and store them in the request object.
		try {
			// Go to the "Welcome" view.
		    String viewPage = ViewAddressFactory.instance().getWelcome();
			RequestDispatcher dispatcher = getRequest().getRequestDispatcher(viewPage);
				dispatcher.forward(getRequest(), getResponse());
		}
//		catch (ServiceExecutionException e) {
//			throw new ControllerExecutionException("Service logic experienced an exception");
//		}
		catch (ServletException e) {
			e.printStackTrace();
			throw new ControllerExecutionException("Controller experienced a ServletException!!");
		}
		catch (IOException e) {
			e.printStackTrace();
			throw new ControllerExecutionException("Controller experienced an IOException!!");
		}
	}
}
